package com.wlyuan.open.controller;

import com.wlyuan.open.api.IOpenApiDocService;
import com.wlyuan.open.dto.api.OpenApiDocFilterDTO;
import com.wlyuan.open.vo.OpenApiDocDetailVO;
import com.wlyuan.open.vo.OpenApiDocVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lijing
 */
@Slf4j
@Api(tags = "接口文档")
@Validated
@RequestMapping("/doc")
@RestController
public class OpenApiDocController {
    @DubboReference(check = false)
    private IOpenApiDocService openApiDocService;

    @ApiOperation("获取所有api（左侧文档菜单）")
    @PostMapping("/getDocMenu")
    public List<OpenApiDocVO> getAllApi(@RequestBody OpenApiDocFilterDTO filter) {
        return openApiDocService.getApiDocList(filter);
    }

    @ApiOperation("接口文档内容获取")
    @GetMapping("/{apiId:\\d+}")
    public OpenApiDocDetailVO getByApiId(@PathVariable("apiId") Long apiId) {
        return openApiDocService.getByApiId(apiId);
    }
}
